﻿using FluentFTP;
using RuYiAdmin.Net.Common.Global;
using System;

namespace RuYiAdmin.Net.Common.Utility
{
    /// <summary>
    /// Ftp工具类
    /// </summary>
    public class RuYiFtpContext
    {
        /// <summary>
        /// Lazy对象
        /// </summary>
        private static readonly Lazy<FtpClient> LazyInstance = new Lazy<FtpClient>(() =>
        {
            var client = new FtpClient(RuYiAdminGlobalContext.FtpConfig.Host);
            if (!String.IsNullOrEmpty(RuYiAdminGlobalContext.FtpConfig.UserName) && !String.IsNullOrEmpty(RuYiAdminGlobalContext.FtpConfig.Password))
            {
                client = new FtpClient(RuYiAdminGlobalContext.FtpConfig.Host,
                                       RuYiAdminGlobalContext.FtpConfig.UserName,
                                       RuYiAdminGlobalContext.FtpConfig.Password
                    );
            }
            return client;
        });

        /// <summary>
        /// 单例对象
        /// </summary>
        public static FtpClient Instance { get { return LazyInstance.Value; } }

        /// <summary>
        /// 是否已创建
        /// </summary>
        public static bool IsInstanceCreated { get { return LazyInstance.IsValueCreated; } }
    }
}
